var AddUser = (function(){
	var ajaxMethod = "POST";
	var url = "http://192.168.10.63:9988/ssm-maven-project/customer/save.json";
	var $addForm = $("#addUserForm");
	var $loading;
	var loadingContent = "正在保存,请稍候....";
	var successUrl = "index.html";

	return {
		init : function(){
			this.validate();
		},
		validate : function(){
			_this = this;
			$addForm.Validform({
				callback:function(form){	// 验证通过的回调函数
					console.log(form);
					_this.submit();			// 提交表单
					return false;
				}
			});
		},
		submit : function(){
			_this = this;
			// 显示加载框
			_this.showLoading();
			var param = $addForm.formToObject();	// 获取到表单参数对象
			console.log(param);
			param = {
				name : 'ajaxAddTest',
				phone : '15818181818'
			};
			// 发送AJAX请求
			$.ajax({
                type: ajaxMethod,
                url: url,
                data: param,
                success: function(result){
					_this.handle(result);			// 处理响应结果
                },
                error: function(xhr, textStatus, ex) {
					// 隐藏加载框
					_this.hideLoading();
                    alert('error.......');
                }
            });
		},
		handle : function(result){
			// 隐藏加载框
			_this.hideLoading();
			console.log(result);
			if(result.success){
				bootbox.alert({
					message: result.message,
					backdrop : true,
					className : 'successTip',
					callback: function(){
						location.replace(successUrl);
					}
				});
				window.setTimeout(function(){
					location.replace(successUrl);
				},2000);
			}else{
				alert(result.message);
			}
		},
		showLoading : function(){
			$loading = bootbox.dialog({
				message : loadingContent,
				closeButton : true,
				className : 'loading',
				buttons : {}
			});
		},
		hideLoading : function(){
			$loading.modal("hide");
		}
	
	};
})();